package model;

import entity.ClassRoomBlock;
import iface.IModel;
import javax.swing.DefaultListModel;

/**
 *
 * @author Noi
 */
public class ClassRoomBlockListModel extends DefaultListModel<ClassRoomBlock> implements IModel<ClassRoomBlock> {

    private manager.Manager manager;
    
    public ClassRoomBlockListModel(manager.Manager manager) {
        this.manager = manager;
        this.loadDataToList();
    }
    
    private void loadDataToList() {
        for (int i = 0; i < this.manager.getClassRoomBlockManager().size(); i++) {
            if (this.manager.getClassRoomBlockManager().get(i).isStatus()) {
                this.addElement(this.manager.getClassRoomBlockManager().get(i));
            }
        }
    }
    
    @Override
    public void add(ClassRoomBlock block) {
        this.manager.getClassRoomBlockManager().add(block);
        this.addElement(block);
    }
    
    @Override
    public void replace(int index, ClassRoomBlock block) {
        this.set(index, block);
    }
    
    @Override
    public void remove(ClassRoomBlock obj) {
        this.manager.getClassRoomBlockManager().setVisible(obj, false);
        this.removeElement(obj);
    }
    
    @Override
    public void refresh() {
        this.removeAllElements();
        this.loadDataToList();
    }
}
